package com.juyu.miliao.api.dao.mysql;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.juyu.miliao.api.domain.BillDetailDeposit;
import com.juyu.miliao.common.domain.BillDetailBeans;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.juyu.miliao.api.domain.BillDetail;

@Repository
public class BillDetailDao {
	@Autowired
	private SqlSession sqlSession;

	public int insertBillDetail(BillDetail billDetail){
		return sqlSession.insert("insertBillDetail", billDetail);
	}

	public BillDetail findDiamondSumByDay(int userId, String threeWeeks, String tomorrow){
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("day", threeWeeks);
		params.put("tomorrow", tomorrow);
		return sqlSession.selectOne("findDiamondSumByDay", params);
	}

	public BillDetail findSpendSumByDay(int userId, String threeWeeks, String tomorrow){
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("day", threeWeeks);
		params.put("tomorrow", tomorrow);
		return sqlSession.selectOne("findSpendSumByDay", params);
	}

	public List<BillDetail> getBillDetailByUserId(int userId, int startNum, int pageSize){
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("startNum", startNum);
		params.put("pageSize", pageSize);
		return sqlSession.selectList("getBillDetailByUserId", params);
	}

	public List<BillDetail> getRedPacketRecordById(int userId, int startNum, int pageSize){
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("startNum", startNum);
		params.put("pageSize", pageSize);
		return sqlSession.selectList("getRedPacketRecordById", params);
	}

    public List<BillDetail> getBillDetailForUser(long id, int startNum, int pageSize) {
		Map<String, Object> params = new HashMap<>();
		params.put("userId", id);
		params.put("startNum", startNum);
		params.put("pageSize", pageSize);
		return sqlSession.selectList("getBillDetailForUser", params);
    }

	public int insertBillDetailDeposit(BillDetailDeposit billDetailDeposit) {
		return sqlSession.insert("insertBillDetailDeposit", billDetailDeposit);
	}

    public List<BillDetailBeans> getBillDetailBeansByUserId(long userId, int startNum, Integer pageSize) {
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("startNum", startNum);
		params.put("pageSize", pageSize);
		return sqlSession.selectList("getBillDetailBeansByUserId", params);
    }

	public int insertBillDetailBeans(BillDetailBeans billDetailBeans) {
		return sqlSession.insert("insertBillDetailBeans", billDetailBeans);
	}

	public List<BillDetailDeposit> getBillDetailDepositByUserId(long userId, int startNum, Integer pageSize) {
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("startNum", startNum);
		params.put("pageSize", pageSize);
		return sqlSession.selectList("getBillDetailDepositByUserId", params);
	}
}
